1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor;
9
10 import org.apache.log4j.Appender;
11 import org.apache.log4j.Category;
12 import org.apache.log4j.ConsoleAppender;
13 import org.apache.log4j.PatternLayout;
14
15
16 /***
17 * Implements some functionality useful when developing and debugging the Angkor framework.
18 *
19 * <!-- $Id: Debug.java,v 1.5 2002/10/13 19:59:22 tirsen Exp $ -->
20 *
21 * @author $Author: tirsen $
22 * @version $Revision: 1.5 $
23 */
24 public class Debug
25 {
26 private static final Category logger = getCategory();
27
28 static
29 {
30 initDebug();
31 }
32
33 public static Category getCategory()
34 {
35 initDebug();
36 return Category.getInstance(Debug.LOGGER_NAME);
37 }
38
39 protected static String CONSOLE_APPENDER = "angkor.console.appender";
40 protected static String CONSOLE_PATTERN = "[%x (%c{1})] %m%n";
41
42 public static final String LOGGER_NAME = "com.tirsen.angkor";
43 private static final boolean DEBUG = false;
44
45 private static boolean inited = false;
46
47 static
48 {
49 initDebug();
50 }
51
52 public static void initDebug()
53 {
54 if (DEBUG & !inited)
55 {
56 System.out.println("loading debug");
57
58 //we need at least one appender so we can log before, during loading
59 //configuration.
60 Appender append = new ConsoleAppender(new PatternLayout(CONSOLE_PATTERN));
61 append.setName(CONSOLE_APPENDER);
62
63 //if no appenders, add at least one
64 if (!Category.getRoot().getAllAppenders().hasMoreElements())
65 {
66 Category.getRoot().addAppender(append);
67 }
68
69 /*
70 logger.setLevel(Level.ALL);
71 ConsoleHandler allHandler = new ConsoleHandler();
72 allHandler.setLevel(Level.ALL);
73 logger.setUseParentHandlers(false);
74
75 // set this handler as the only handler for this logger
76 Handler[] handlers = logger.getHandlers();
77 for(int i = 0; i < handlers.length; i++)
78 {
79 Handler handler = handlers[i];
80 logger.removeHandler(handler);
81 }
82 logger.addHandler(allHandler);
83
84 inited = true;
85 */
86 }
87 }
88 }
This page was automatically generated by Maven